from rest_framework import serializers
from xyz.models import Article,User,Comment


class ArtiClesializer(serializers.ModelSerializer):
    class Meta:
        model=Article
        fields=['id','title']



class Usersializer(serializers.ModelSerializer):
    article = ArtiClesializer(read_only=True)
    class Meta:
        model=User
        fields=['id','username','avatar','article','fans']


class Subssializer(serializers.ModelSerializer):
    user = Usersializer(read_only=True)
    class Meta:
        model=Comment
        fields=['id','content','article','user','parent','subs']


class CommentSerializer(serializers.ModelSerializer):

    user = Usersializer(read_only=True)
    subs = Subssializer(read_only=True,many=True)
    class Meta:
        model = Comment
        fields=['id','user','content','createtime','updatetime','parent','article','subs']


class ArticleContentSerializer(serializers.ModelSerializer):

    '''文章详情'''
    user = Usersializer(read_only=True)
    comments = CommentSerializer(read_only=True,many=True)
    # labels = serializers.StringRelatedField(many=True)

    class Meta:
        model = Article
        fields = '__all__'



#
# class CommentSerializer(serializers.ModelSerializer):
#     subs=serializers.StringRelatedField(many=True)
#     user=Usersializer()
#     class Meta:
#         model = Comment
#         fields='__all__'
